/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.camelotone.ejb.session;

import it.camelotone.ejb.entity.Friend;
import it.camelotone.util.ConnectionProvider;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.persistence.Query;

/**
 *
 * @author fabiomassimo
 */
@Stateless
@Local(SalutationLocal.class)
public class Salutation implements SalutationLocal {
	
	@PersistenceUnit
	private EntityManagerFactory factory;
	
	public final static String QUERY_TXT = "select f from Friend f";

    public String getFormalSalutation(String name) {
        return "Dear " + name;
    }

    public String getInformalSalutation(String name) {
        return "Hi " + name;
    }
    
    @Override
    public Friend getFirstFriend() {
    	
    	EntityManager entityManager = factory.createEntityManager();
		final Query query = entityManager.createQuery(QUERY_TXT);
		return (Friend) query.getResultList().get(0);
		
    }

}
